<?php /*
	*/ ?>
<?php include("system/config.inc.php");
$donotinclude = 1;
if(!isset($_SESSION['adminuserid']))
{
	header("location:index.php?msg=logfirst");
	die();
}
?>
<?php include("inc/header.php");?>
<body>
<style type="text/css">
<!--
.style1 {
	color: #000000;
	font-weight: bold;
}
.style3 {color: #000000}
.style4 {
	font-size: 16px;
	font-weight: bold;
}
-->
</style>
<table width="80%" border="0" align="center" cellpadding="0" cellspacing="1" class="middlebackground">
  <tr>
    <td colspan="3" valign="top" align="center">&nbsp;</td>
  </tr>
  <?php
  	$sql7 = "SELECT * FROM `tblmystore`";
		$res=$obj_db->select($sql7);	
		if($sql7)
			{			
				for($j=0;$j<count($res);$j++)
				{
  ?>
  <tr>
    <td colspan="2" valign="top" align="left"><table width="80%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td align="left" class="font"><strong><?php echo stripslashes($res[$j]['varstoreownername']);?>,</strong> </td>
      </tr>
      <tr>
        <td align="left" class="font"><strong><?php echo stripslashes($res[$j]['varstorename']);?>,</strong>
         </td>
      </tr>
      <tr>
        <td align="left" class="font"><strong><?php echo stripslashes($res[$j]['varstoreaddsandphone']);?>,</strong>
          </td>
      </tr>
      <tr>
        <td align="left" class="font"><strong><?php echo stripslashes($res[$j]['varzone']);?>,</strong>
           </td>
      </tr>
      <tr>
        <td align="left" class="font"><strong><?php echo stripslashes($res[$j]['varcountry']);?>,</strong>
          </td>
      </tr>
	   <tr>
        <td align="left" class="font"><strong><?php echo stripslashes($res[$j]['varpostcode']);?></strong>
          </td>
      </tr>
	  <tr><td><br /></td></tr>
      <tr>
        <td align="left" class="font"><strong><?php echo stripslashes($res[$j]['varsendordertoemail']);?></strong>
          </td>
      </tr>
    </table></td>
    <td width="34%" align="center" valign="top"> <span class="style4">INVOICE</span>  </td>
  </tr>
  <?php }} ?>
  <tr>
    <td colspan="3" align="left" valign="top" class="sltimg"><p>(This  is the registered office not the trading address,<br />
  &nbsp;please  see website for trading address)</p></td>
  </tr>
  <tr>
    <td colspan="3" valign="top" align="center">&nbsp;</td>
  </tr>
  <tr>
    
    <td align="left" colspan="3"><table width="100%" border="0" align="left" cellpadding="2" cellspacing="2">
      <tr>
        <td height="20" colspan="3" bgcolor="#FFFFFF"><span class="style1">Orders</span></td>
        <td align="center" bgcolor="#FFFFFF"><a href="javascript:print();" Title='Click here to take a Print' class="style3">Print</a></td>
      </tr>
      <tr>
        <td colspan="4"><table width="100%" border="0" cellpadding="2" cellspacing="2" class="border">
          <tr>
            <td width="23%" valign="top" class="font"><strong>Invoice Address:</strong></td>
            <?php
		if(isset($_REQUEST['order']) && ($_REQUEST['order'])!="")
		{
		
			$sql = "SELECT * FROM `tblorders` WHERE `intid`=".mysql_real_escape_string($_REQUEST['order']);
			$result = $obj_db->select($sql);
			if(count($result)>0)
			{
				for($i=0;$i<count($result);$i++) { 
			?>
            <td width="25%" align="left">
			  <?php echo stripslashes($result[$i]['varbillingname']);?><br />
              <?php echo stripslashes($result[$i]['varbillingstreetaddress']);?><br />
              <?php echo stripslashes($result[$i]['varbillingcity']); ?><br /><?php echo stripslashes($result[$i]['varbillingpostcode']);?><br /><?php echo stripslashes($result[$i]['varbillingstate']); ?><br /><?php echo stripslashes($result[$i]['varbillingcountry']); ?></td>
			<?php	}
			}
		}
		?>
            <td width="22%" valign="top" class="font"><strong>Delivery Address:</strong></td>

            <?php
if(isset($_REQUEST['order']) && ($_REQUEST['order'])!="")
{
	$sql1 = "SELECT * FROM `tblorders` WHERE intid=".mysql_real_escape_string($_REQUEST['order']);
	$result1 = $obj_db->select($sql1);
	if(count($result1)>0)
	{
	for($i1=0;$i1<count($result1);$i1++)
	 { 
?>

            <td colspan="3" align="left">
			<?php echo stripslashes($result[$i1]['vardeliveryname']);?><br />
            <?php echo stripslashes($result1[$i1]['vardeliverystreetaddress']);?><br />
              <?php echo stripslashes($result1[$i1]['vardeliverycity']); ?><br /><?php echo stripslashes($result1[$i1]['vardeliverypostcode']);?><br /><?php echo stripslashes($result1[$i1]['vardeliverystate']); ?><br /><?php echo stripslashes($result1[$i1]['vardeliverycountry']);?></td>
			  <?php }} } 
if(isset($_REQUEST['order']) && ($_REQUEST['order'])!="")
{
	$sql2 = "SELECT * FROM `tblorders` WHERE `intid`=".mysql_real_escape_string($_REQUEST['order']);
	$result2 = $obj_db->select($sql2);
	if(count($result2)>0)
	{
	for($i2=0;$i2<count($result2);$i2++)
	 { 
		$shipmehtd=stripslashes($result2[$i2]['shipmethod']);
		$discountcode=$result2[$i2]['discountcode'];
?>
          </tr>
          <tr>
            <td class="font"><strong>Telephone:</strong></td>
            <td align="left"><?php echo stripslashes($result2[$i2]['varcustomertelephone']);?></td>
            <td>&nbsp;</td>
            <td width="3%">&nbsp;</td>
            <td width="10%">&nbsp;</td>
            <td width="17%">&nbsp;</td>
          </tr>
          <tr>
            <td class="font"><strong>E-Mail:</strong></td>
            <td align="left" colspan="5"><?php echo stripslashes($result2[$i2]['varcustomeremailid']);?></td>
          </tr>
        </table>
		
		</td>
        </tr>
      <tr>
        <td colspan="4">&nbsp;</td>
      </tr>
      <tr>
        <td colspan="4" class="fntstyle"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="border">
          <tr>
            <td width="39" valign="top" class="sltimg">&nbsp;</td>
            <td width="170" valign="top" class="sltimg"><strong>Page number</strong></td>
            <td width="152" valign="top" class="sltimg">1 of 1</td>
            <td width="108" valign="top" class="sltimg"><strong>Order Number</strong></td>
            <td width="117" valign="top" class="sltimg"><?php echo stripslashes($_REQUEST['order']);?></td>
          </tr>
          <tr>
            <td width="39" valign="top" class="sltimg">&nbsp;</td>
            <td width="170" valign="top" class="sltimg"><strong>Customer Email</strong></td>
            <td width="152" valign="top" class="sltimg"><?php echo stripslashes($result2[$i2]['varcustomeremailid']);?></td>
            <td width="108" valign="top" class="sltimg"><strong>Order Date</strong></td>
            <td width="117" valign="top" class="sltimg"><?php echo stripslashes(printdate($result2[$i2]['dtfinished']));?> </td>
          </tr>
          <tr>
            <td width="39" valign="top" class="sltimg">&nbsp;</td>
            <td width="170" valign="top" class="sltimg"><strong>Payment Method</strong></td>
            <td width="152" valign="top" class="sltimg"><?php echo stripslashes($result2[$i2]['varpaymentmethod']);?></td>
            <td colspan="2" valign="top" class="sltimg">For Returns Please see website.</td>
          </tr>
		  <tr>
		  <td width="39" valign="top" class="sltimg">&nbsp;</td>
            <td width="170" valign="top" class="sltimg"><strong>Shipping Method</strong></td>
            <td width="152" valign="top" class="sltimg" colspan=2>
		  <?php  $sqlm="select * from tblshippingmaster where intid=$shipmehtd";
				 $resm=$obj_db->select($sqlm);
				 if($resm) {
					$charge=$resm[0]['decshipcost'];
				 } else {
					$charge=0.00;
				 }
				 echo "&pound;".number_format($charge, 2, '.', '')." - ".stripslashes($resm[0]['vartitle'])." - ".stripslashes($resm[0]['vardesc']);
			?></td>
            <td valign="top" class="sltimg">&nbsp;</td>
		  </tr>
		   <tr>
		  <td width="39" valign="top" class="sltimg">&nbsp;</td>
            <td width="170" valign="top" class="sltimg"><strong>Total value of order</strong></td>
            <td width="152" valign="top" class="sltimg" colspan=2>
		  <?php echo "&pound;".number_format($result2[$i2]['totalvalue'], 2, '.', '');?></td>
            <td valign="top" class="sltimg">&nbsp;</td>
		  </tr>
        </table>
		
		</td>
        </tr>
      <tr>
        <td colspan="4">&nbsp;</td>
      </tr><?php }} } ?>
      <tr>
        <td colspan="4">
		
		<table width="100%" border="0" cellpadding="0" cellspacing="2" class="border">
          <tr>
            <td align="center" class="border"><strong>Product Code</strong></td>
            <td align="center" class="border"><strong>Quantity</strong></td>
            <td align="center" class="border"><strong>Name</strong></td>
			<td align="center" class="border"><strong>Unit Price</strong></td>
			<td align="center" class="border"><strong>Options</strong></td>
			<td align="center" class="border"><strong>Unit Price inc options</strong></td>
			<td align="center" class="border"><strong>Quantity Price</strong></td>
          </tr>
		  <?php 
		  if(isset($result1[0]['intid']) && ($result1[0]['intid'])!="") {
					$id=$result1[0]['intid'];
		  			$sum=0;
					$sql3 = "SELECT * FROM `tblorderproducts` WHERE `intorderid`=$id";
					$vat=0;
					$result3 = $obj_db->select($sql3);
					if(count($result3)>0) {
						for($i3=0;$i3<count($result3);$i3++) {
		  ?>
          <tr>
            <td align="center" class="sltimg"><?php echo stripslashes($result3[$i3]['intproductid'])?></td>
            <td align="center" class="sltimg"><?php echo stripslashes($result3[$i3]['intquantity'])?></td>
            <td align="center" class="sltimg"><?php 
			$prid= $result3[$i3]['intproductid'];
			$sqlpr="select `varprodname`,`txtdesc` from tblproddesc where intid='$prid'";
			$respr=$obj_db->select($sqlpr);
			if($respr) {
				echo stripslashes($respr[0]['varprodname']);
			}
			?></td>
			<td align="center" class="sltimg">
			<?php
			$sqlpr="SELECT `decprice` FROM `tblproducts` WHERE intprodid='$prid'";
			$respr=$obj_db->select($sqlpr);
			if($respr) {
				echo stripslashes($respr[0]['decprice']);
			}
			$pricewithoptions = $respr[0]['decprice'];
			?>
			</td>
			<td align="left" class="sltimg"><ul>
			<?php
				$attributessql = "SELECT * FROM tblorderproductattributes WHERE intorderproductid=".$result3[$i3]['intid'];
				$attributeresult=$obj_db->select($attributessql);
				for($at=0;$at<count($attributeresult);$at++) {
				
					$attributesql1 = "SELECT tblproductattributes.*, tbloptionvalues.varoptionvaluename, tblproductoptions.varoptionname FROM tblproductattributes INNER JOIN tblproductoptions ON tblproductattributes.intoptionvalueid=tblproductoptions.intid INNER JOIN tbloptionvalues ON tblproductattributes.intoptionid=tbloptionvalues.intid  WHERE intattributeid=".$attributeresult[$at]['intproductoptionid'];
					$attributeresult1=$obj_db->select($attributesql1);
					echo "<li><strong>".stripslashes($attributeresult1[0]['varoptionvaluename']).":</strong> ".stripslashes($attributeresult1[0]['varoptionname'])."(".stripslashes($attributeresult1[0]['charprefix'])." &pound;".stripslashes($attributeresult1[0]['decprice']).")</li>";
				
					$pricewithoptions = $pricewithoptions+$attributeresult1[0]['decprice'];
				}
			?>
			</ul>
			</td>
			<td align="center" class="sltimg">
			&pound; <?php echo $pricewithoptions;?>
			</td>
			<td align="center" class="sltimg">
			&pound; <?php echo $pricewithoptions*$result3[$i3]['intquantity'];?>
			</td>
          </tr>
		  <?php 
		  $globaltot = $globaltot + ($pricewithoptions*$result3[$i3]['intquantity']);
		  }}}
		  
		  ?>
        </table></td>
        </tr>
	  <tr>
        <td colspan="2">&nbsp;</td>
        <td width="170" valign="top" align="right" class="sltimg"><strong>Subtotal</strong></td>
        <td width="50" valign="top" align="center" class="sltimg">&pound; <?php echo $globaltot;?></td>
      </tr>
	  <tr>
        <td colspan="2">&nbsp;</td>
        <td width="170" valign="top" align="right" class="sltimg"><strong>Discount</strong></td>
        <td width="50" valign="top" align="center" class="sltimg">&pound; 
		<?php 
		$dis=0.00;
			$sqld="select * from tbldiscountcode where varcode='$discountcode'";
			$resultd=$obj_db->select($sqld);
			if($resultd) {
			$dicode=$resultd[0]['varcode'];
			$discount= $resultd[0]['decdiscount'];
			$type=$resultd[0]['intdesctype'];
			$minbuy=$resultd[0]['decminbuy'];
				if($globaltot>$minbuy) {
					if($type==1) {	
						$dis=($globaltot*$discount)/100;
						echo number_format(round($dis,2), 2, '.', '');
					} else if($type==2) {
						$dis=$discount;
						echo number_format(round($dis,2), 2, '.', '');
					} else {
						$dis=0.00; echo $dis;
					}
				} else {
					$dis=0.00; echo $dis;
				}
			} else {
				$dis=0.00;
			}
		?>
		</td>
      </tr>
	   <tr>
        <td colspan="2">&nbsp;</td>
        <td width="170" valign="top" align="right" class="sltimg"><strong>Shipping</strong></td>
        <td width="50" valign="top" align="center" class="sltimg">&pound; <?php echo number_format($charge, 2, '.', '');?></td>
      </tr>
	   <tr>
        <td colspan="2">&nbsp;</td>
        <td width="170" valign="top" align="right" class="sltimg"><strong>VAT</strong></td>
        <td width="50" valign="top" align="center" class="sltimg">&pound; 
		<?php 
		// calc tax
		$sum = $globaltot+$charge-$dis;
		$taxsql="SELECT * FROM tbltaxrates";
		$taxresults=$obj_db->select($taxsql);
		$vatamount = $taxresults[0]['vatrate'];
		$amountvat = ($sum/100)*$vatamount;
		echo number_format(round($amountvat,2), 2, '.', '');
		?>
		</td>
      </tr>
	  <tr>
        <td colspan="2">&nbsp;</td>
        <td width="170" valign="top" align="right" class="sltimg"><strong>Grand Total</strong></td>
        <td width="50" valign="top" align="center" class="sltimg">&pound; <?php 
		$gt = $globaltot+$charge+$amountvat-$dis;
		echo number_format($gt, 2, '.', '');?>
		</td>
      </tr>
      <tr>
        <td colspan="2">&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td colspan="2">&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td colspan="2">&nbsp;</td>
        <td>&nbsp;</td>
        <td><input name="Button" type="button" value="Close Window" onClick="window.close();"/></td>
      </tr>
    </table>      </td>
    
  </tr>
</table>
</body>
</html>
